package models;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import play.db.jpa.Blob;
import javax.persistence.Entity;

import play.db.jpa.Model;

@Entity
public class User extends Model{
	public String FirstName;
	public String LastName;
	public String UserName;
	public String Password;
	public int ssn;
	public String Address;
	public String Email;
	public int HomeNumber;
	public int MobileNumber;
	public String Country;
	public Blob photo;
	
	@ManyToMany (mappedBy="users")
	public List<Unit> units;
	
	@OneToMany (mappedBy="user")
	public List<Boat> boats;
	
	@OneToMany (mappedBy="user")
	public List<Horse> horses;
	
	public User(LinkedList<Object> attributes)
	{
		
		this.FirstName = (String) attributes.get(0);
		this.LastName = (String) attributes.get(1);
		this.UserName = (String) attributes.get(2);
		this.Password = (String) attributes.get(3);
		this.ssn = 		 (Integer) attributes.get(4);
		this.Address = (String) attributes.get(5);
		this.Email = (String) attributes.get(6);
		this.HomeNumber = (Integer) attributes.get(7);
		this.MobileNumber = (Integer) attributes.get(8);
		this.Country = (String) attributes.get(9);
		
	}
	public boolean HasPhoto()
	{		
		try{ return photo.getFile().isFile();} catch (Throwable e) {return false;}
			
		
	}
	
	public static boolean connect(String username, String password) {
		
		return User.find("UserName = ? and Password = ?", username,password).first() != null;
	
	}


}
